package com.project.srtp.secure.controller;

import com.project.srtp.secure.common.result.Result;
import com.project.srtp.secure.common.result.Results;
import com.project.srtp.secure.dto.req.CreateSessionReqDTO;
import com.project.srtp.secure.dto.req.GetSessionIdReqDTO;
import com.project.srtp.secure.dto.resp.CreateSessionRespDTO;
import com.project.srtp.secure.dto.resp.GetSessionIdRespDTO;
import com.project.srtp.secure.service.SessionService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 曹行阳
 * @version 0.1
 * @date 2025/6/16 18:27
 */
@RestController
@RequiredArgsConstructor
public class SessionController {

    private final SessionService sessionService; // 会话管理服务

    /**
     * 创建新会话
     *
     * @param request 包含会话创建参数的请求体
     * @return 包含新会话信息的响应结果
     *
     */
    @PostMapping("/api/session/createSession")
    public Result<CreateSessionRespDTO> createSession(@RequestBody CreateSessionReqDTO request) {
        return Results.success(sessionService.createSession(request));
    }

    /**
     * 获取会话ID
     *
     * @param request 包含会话查询条件的请求体
     * @return 会话ID字符串
     *
     */
    @PostMapping("/api/session/getSessionId")
    public Result<String> getSessionId(@RequestBody GetSessionIdReqDTO request) {
        return Results.success(sessionService.getSessionId(request));
    }

    /**
     * 获取用户所有会话
     *
     * @param userId 用户ID（路径变量）
     * @return 用户参与的所有会话列表
     *
     */
    @GetMapping("/api/session/getAllSessions/{userId}")
    public Result<List<GetSessionIdRespDTO>> getAllSessionId(@PathVariable String userId) {
        return Results.success(sessionService.getAllSessionId(userId));
    }
}
